﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ProductCopy.ascx.cs" Inherits="admin_webparts_Plug_ins_Product_ProductCopy" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="NTTHAO.CommonWeb" %>
<%@ Import Namespace="NTTHAO.Common.BL" %>
<%@ Import Namespace="NTTHAO.Web.BL.Product" %>
    <link href="resources/js/jQuery.Treeview/jquery.treeview.css" rel="stylesheet" type="text/css" />
<%if (this._Type != null)
  { %>
<style type="text/css">
    #spCancel1, #spSave, #spCancel2, #spSave2 {font-size:1.1em; font-weight: bold; }
    #spCancel1 button, #spSave button, #spCancel2 button, #spSave2 button { font-family: Verdana,Arial,Helvetica,sans-serif; font-weight: bold; }
</style>
<form id="frmInput" runat="server" onsubmit="return doSubmitCopyFrom();">
<script type="text/javascript">
function doSubmitCopyFrom() {
<% 
    if (_Step == 1) 
    { 
%>
    var checked = false;
    var chks = document.getElementsByName('chkId');
    if (chks != null && chks.length > 0) {
        for (var i = 0; i < chks.length; i++) {
            if (chks[i].checked) {
                checked = true;
                break;
            }
        }
    }
    if (!checked) {
        alert("Vui lòng chọn sản phẩm.");
        return false;
    }
<%
    }
    else if (_Step == 2)
    {
%>
<%
    }
    else if (_Step == 3)
    {
%>
<%
    }
%>
    return true;
}
function checkAll(checked) {
//    if (!checked) {
//        return;
//    }
    var chks = document.getElementsByName('chkId');
    if (chks != null && chks.length > 0) {
        for (var i = 0; i < chks.length; i++) {
            chks[i].checked = checked;
        }
    }
}
function checkItem(checked) {
    if (!checked) {
        document.getElementById('chkAll').checked = false;
    }
}
function selectType(typeID) {
    if(typeID == <%=this._Type.ID.ToString("0") %>) {
        alert("Không được <%=this._MethodName.ToLower() %> vào chính nó.");
        return;
    }
    var chkIds = document.getElementById('chkId').value;
    var rdMethod = document.getElementById('rdMethod').value;
    var url = 'ProductContent.aspx' + window.location.search + '&step=4&chkId=' + encodeURIComponent(chkIds) + '&totype=' + typeID + '&rdMethod=' + rdMethod;
    location.href = url;
    return false;
}
function copyNow() {
    var chkIds = document.getElementById('chkId').value;
    var rdMethod = document.getElementById('rdMethod').value;
    var copyToTypeID = document.getElementById('copyToTypeID').value;
    var url = 'ProductContent.aspx' + window.location.search.split('&step=')[0] + '&step=5&chkId=' + encodeURIComponent(chkIds) + '&totype=' + copyToTypeID + '&rdMethod=' + rdMethod;
    location.href = url;
    return false;
}
</script>
<% 
    if (_Step == 1) 
    { 
%>
<div class="tip">
	<h2 style="padding-top: 2px;">Chọn sản phẩm và phương thức mà bạn muốn thực hiện</h2>
</div>
<p style="text-align: left;">
    <span id="spSave" class="yui-button yui-link-button yuibtn yuibtn-icon btnnext2"><span class="first-child"><asp:Button ID="btnCopyFrom" runat="server" OnClick="btnCopyFrom_Click" Text="Copy" /></span></span>
    <span id="spCancel1" class="yui-button yui-link-button yuibtn yuibtn-icon btncancel"><span class="first-child"><a href="?action=view&g=<%=Request.QueryString["g"] %>&typeid=<%=Request.QueryString["typeid"] %>"><%=LanguageUtility.GetLanguageText("CANCEL", Session)%></a></span></span>
    <script type="text/javascript">
        YAHOO.util.Event.onContentReady("spSave", function () {
            var spSave = new YAHOO.widget.Button("spSave");
        });
        YAHOO.util.Event.onContentReady("spCancel1", function () {
            var spCancel1 = new YAHOO.widget.Button("spCancel1");
        });
    </script>
</p>
<div class="tip">
    <div style="padding-bottom: 5px;color: #E76300; font-size: 1.2em; font-weight: bold;">Phương thức</div>
    <table class="grid" border="1" cellpadding="0" cellspacing="0">
        <tr class="odd" style="height: 54px;">
            <td width="1%" nowrap="nowrap">Phương thức: </td>
            <td><b>
                <input type="radio" id="rdMethod1" name="rdMethod" value="0" checked="checked" /> <label for="rdMethod1">Sao chép</label><br />
                <input type="radio" id="rdMethod2" name="rdMethod" value="1" /> <label for="rdMethod2">Di chuyển</label>
            </b></td>
        </tr>
    </table>
</div>
<table id="tbGrid" class="grid" border="1" cellpadding="0" cellspacing="0">
    <tr>
        <th width="42px"><input type="checkbox" id="chkAll" name="chkAll" value="1" onclick="checkAll(this.checked);" /></th>
        <th><%=LanguageUtility.GetLanguageText("PRODUCT_ID", Session)%></th>
        <th><%=LanguageUtility.GetLanguageText("NAME", Session)%></th>
        <th><%=LanguageUtility.GetLanguageText("IMAGE", Session)%></th>
    </tr><% if (this._Products != null) for (int i = 0; i < this._Products.Rows.Count; i++)
       {
           System.Data.DataRow row = this._Products.Rows[i];
           int id = (int)row[Product.ID__COLUMN_NAME];
           string proID = row[Product.PRODUCTID__COLUMN_NAME].ToString();
           string name = row[Product.PRODUCTNAME__COLUMN_NAME].ToString();
           string imagePath = row[Product.IMAGEPATH__COLUMN_NAME].ToString();
           string image = row[Product.IMAGE__COLUMN_NAME].ToString();
           %>
    <tr class="<%=(i%2==1?"even":"odd") %>">
        <td align="center"><input type="checkbox" name="chkId" value="<%=id.ToString("0") %>" onclick="checkItem(this.checked);" /></td>
        <td><%=proID%></td>
        <td><%=name%></td>
        <td align="center"><img class="mw100 mh100" alt="" src="<%=this._ProductUploadeFolder + imagePath + image %>" /></td>
    </tr>
    <%} %>
</table>
<p style="text-align: left;">
    <span id="spSave2" class="yui-button yui-link-button yuibtn yuibtn-icon btnnext2"><span class="first-child"><asp:Button ID="btnCopyFrom2" runat="server" OnClick="btnCopyFrom_Click" Text="Copy" /></span></span>
    <span id="spCancel2" class="yui-button yui-link-button yuibtn yuibtn-icon btncancel"><span class="first-child"><a href="?action=view&g=<%=Request.QueryString["g"] %>&typeid=<%=Request.QueryString["typeid"] %>"><%=LanguageUtility.GetLanguageText("CANCEL", Session)%></a></span></span>
    <script type="text/javascript">
        YAHOO.util.Event.onContentReady("spSave2", function () {
            var spSave2 = new YAHOO.widget.Button("spSave2");
        });
        YAHOO.util.Event.onContentReady("spCancel2", function () {
            var spCancel2 = new YAHOO.widget.Button("spCancel2");
        });
    </script>
</p>
<%
    }
    else if (_Step == 2)
    {
%>
<div class="tip">
	<h2 style="padding-top: 2px;">Chọn ngôn ngữ bạn muốn <%=this._MethodName.ToLower() %> đến</h2>
</div>
<table id="tbGrid" class="grid" border="1" cellpadding="0" cellspacing="0">
    <tr class="odd">
        <td width="1%" nowrap="nowrap"><%=LanguageUtility.GetLanguageText("SELECT_LANGUAGE", Session)%>:</td>
        <td>
            <asp:DropDownList ID="cmbLaguage" runat="server" Width="200px">
            </asp:DropDownList></td>
    </tr>
</table>
<p style="text-align: left;">
    <input type="hidden" id="rdMethod" name="rdMethod" value="<%=Request.Params["rdMethod"] %>" />
    <input type="hidden" name="chkId" value="<%=Request.Params["chkId"] %>" />
    <span id="spSave" class="yui-button yui-link-button yuibtn yuibtn-icon btnnext2"><span class="first-child"><asp:Button ID="btnSite" runat="server" OnClick="btnSite_Click" Text="OK" /></span></span>
    <span id="spCancel1" class="yui-button yui-link-button yuibtn yuibtn-icon btncancel"><span class="first-child"><a href="?action=view&g=<%=Request.QueryString["g"] %>&typeid=<%=Request.QueryString["typeid"] %>"><%=LanguageUtility.GetLanguageText("CANCEL", Session)%></a></span></span>
    <script type="text/javascript">
        YAHOO.util.Event.onContentReady("spSave", function () {
            var spSave = new YAHOO.widget.Button("spSave");
        });
        YAHOO.util.Event.onContentReady("spCancel1", function () {
            var spCancel1 = new YAHOO.widget.Button("spCancel1");
        });
    </script>
</p>
<%
    }
    else if (_Step == 3)
    {
%>
    <input type="hidden" id="rdMethod" name="rdMethod" value="<%=Request.Params["rdMethod"] %>" />
    <input type="hidden" id="chkId" name="chkId" value="<%=Request.Params["chkId"] %>" />
<div class="tip">
	<h2 style="padding-top: 2px;">Chọn nhóm sản phẩm bạn muốn <%=this._MethodName.ToLower() %> đến</h2>
</div>
<ul class="filetree treeview" style="border: solid 1px #89D; font-size: 1.2em;">
<%
if (this._Group != null) 
{
    try
    {
        DataSet mds = ProductType.GetAllRootByGroup(this._Group.ID);
        if (mds != null && mds.Tables[0].Rows.Count > 0) 
        {
            for (int i = 0; i < mds.Tables[0].Rows.Count; i++)
            {
                DataRow row = mds.Tables[0].Rows[i];
                string id = ((int)row[ProductType.ID__COLUMN_NAME]).ToString("0");
                string text = row[ProductType.NAME__COLUMN_NAME].ToString();

                DataSet sds = ProductType.GetAllByParent(Convert.ToInt32(id));
                if (sds != null && sds.Tables[0].Rows.Count < 1)
                {
                    sds = null;
                }

                if (sds != null)
                {
%>	        <li class="collapsable <%=(i == mds.Tables[0].Rows.Count - 1 ? "last" : "")%>">		        <div class="hitarea collapsable-hitarea"></div>		        <span class="folder"><a href="#" onclick="return selectType(<%=id %>);"><%=text%></a></span>		        <ul><%                    for (int j = 0; j < sds.Tables[0].Rows.Count; j++)
                    {
                        DataRow rowj = sds.Tables[0].Rows[j];
                        string idj = ((int)rowj[ProductType.ID__COLUMN_NAME]).ToString("0");
                        string textj = rowj[ProductType.NAME__COLUMN_NAME].ToString();

                        DataSet sdj = ProductType.GetAllByParent(Convert.ToInt32(idj));
                        if (sdj != null && sdj.Tables[0].Rows.Count < 1)
                        {
                            sdj = null;
                        }

                        if (sdj != null)
                        {
%>                    <li class="collapsable <%=(j == sds.Tables[0].Rows.Count - 1 ? "last" : "")%>">	                    <div class="hitarea collapsable-hitarea"></div>	                    <span class="folder"><a href="#" onclick="return selectType(<%=idj %>);"><%=textj%></a></span>	                    <ul><%                            for (int k = 0; k < sdj.Tables[0].Rows.Count; k++)
                            {
                                DataRow rowk = sdj.Tables[0].Rows[k];
                                string idk = ((int)rowk[ProductType.ID__COLUMN_NAME]).ToString("0");
                                string textk = rowk[ProductType.NAME__COLUMN_NAME].ToString();
%>			                <li class="<%=(k == sdj.Tables[0].Rows.Count - 1 ? "last" : "")%>"><span class="file"><a href="#" onclick="return selectType(<%=idk %>);"><%=textk %></a></span></li><%
                            }
%>		                </ul>	                </li><%
                    }
                    else 
                    {
%>			        <li class="<%=(j == sds.Tables[0].Rows.Count - 1 ? "last" : "")%>"><span class="file"><a href="#" onclick="return selectType(<%=idj %>);"><%=textj %></a></span></li><%
                        }                    }
%>		        </ul>	        </li><%                } else {
%>            <li class="<%=(i == mds.Tables[0].Rows.Count - 1 ? "last" : "")%>">                <span class="file"><a href="#" onclick="return selectType(<%=id %>);"><%=text%></a></span>            </li><%                }            }        }    }
    catch { }}%></ul>
<%
    }
    else if (_Step == 4)
    {
%>
<div class="tip">
	<h2 style="padding-top: 2px;">Xác nhận <%=this._MethodName.ToLower() %> sản phẩm</h2>
</div>
<p style="text-align: left;">
    <input type="hidden" id="rdMethod" name="rdMethod" value="<%=Request.Params["rdMethod"] %>" />
    <input type="hidden" id="chkId" name="chkId" value="<%=_SelectedItems %>" />
    <input type="hidden" id="copyToTypeID" name="copyToTypeID" value="<%=_CopyToTypeID %>" />
    <span id="spSave" class="yui-button yui-link-button yuibtn yuibtn-icon <%=_Method==1?"btnmove":"btncopy" %>"><span class="first-child"><a href="#" onclick="return copyNow();"><%=this._MethodName %></a></span></span>
    <span id="spCancel1" class="yui-button yui-link-button yuibtn yuibtn-icon btncancel"><span class="first-child"><a href="?action=view&g=<%=Request.QueryString["g"] %>&typeid=<%=Request.QueryString["typeid"] %>"><%=LanguageUtility.GetLanguageText("CANCEL", Session)%></a></span></span>
    <script type="text/javascript">
        YAHOO.util.Event.onContentReady("spSave", function () {
            var spSave = new YAHOO.widget.Button("spSave");
        });
        YAHOO.util.Event.onContentReady("spCancel1", function () {
            var spCancel1 = new YAHOO.widget.Button("spCancel1");
        });
    </script>
</p>
<div class="tip">
    <div style="padding-bottom: 5px;color: #E76300; font-size: 1.2em; font-weight: bold;">Từ</div>
<table class="grid" border="1" cellpadding="0" cellspacing="0">
    <tr class="odd">
        <td width="1%" nowrap="nowrap">Ngôn ngữ: </td>
        <td><b><%= LanguageUtility.GetLanguageName(LanguageUtility.GetLanguageID(Request, Session), Session) %></b></td>
    </tr>
    <tr class="even">
        <td width="1%" nowrap="nowrap">Nhóm sản phẩm: </td>
        <td><b><%=_Type.Name%></b></td>
    </tr>
</table>
</div>
<div class="tip">
    <div style="padding-bottom: 5px;color: #E76300; font-size: 1.2em; font-weight: bold;">Đến</div>
<%
    ProductType toType = (new ProductType(_CopyToTypeID));
    ProductGroup toGroup = new ProductGroup(toType.GroupID);
    Language toLang = new Language(toGroup.LanguageID);
%>
<table class="grid" border="1" cellpadding="0" cellspacing="0">
    <tr class="odd">
        <td width="1%" nowrap="nowrap">Ngôn ngữ: </td>
        <td><b><%=toLang.Name %></b></td>
    </tr>
    <tr class="even">
        <td width="1%" nowrap="nowrap">Nhóm sản phẩm: </td>
        <td><b><%=toType.Name%></b></td>
    </tr>
</table>
</div>
<div style="padding-bottom: 10px;color: #E76300; font-size: 1.2em; font-weight: bold;">Danh sách sản phẩm <%=this._MethodName.ToLower() %></div>
<table id="tbGrid" class="grid" border="1" cellpadding="0" cellspacing="0">
    <tr>
        <th width="42px">#</th>
        <th><%=LanguageUtility.GetLanguageText("PRODUCT_ID", Session)%></th>
        <th><%=LanguageUtility.GetLanguageText("NAME", Session)%></th>
        <th><%=LanguageUtility.GetLanguageText("IMAGE", Session)%></th>
    </tr>
<%
    string[] pidList = _SelectedItems.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
    for (int i = 0; i < pidList.Length; i++)
    {
        int pid = 0;
        Int32.TryParse(pidList[i], out pid);
        Product p = new Product(pid);
        if (p.ID > 0)
        {
%>
    <tr class="<%=(i%2==1?"even":"odd") %>">
        <td align="center"><%=(i+1) %></td>
        <td><%=p.ProductID %></td>
        <td><%=p.ProductName %></td>
        <td align="center"><img class="mw100 mh100" alt="" src="<%=this._ProductUploadeFolder + p.ImagePath + p.Image %>" /></td>
    </tr>
<%
        }
    }
%>
</table>
<%
    }
    else if (_Step == 5)
    {
%>
<div class="tip">
	<h2 style="padding-top: 2px;">Đã <%=this._MethodName.ToLower() %> sản phẩm.</h2>
</div>
<div class="tip" style="font-size: 1.2em; font-weight: normal;">Tất cả các sản phẩm bạn đã chọn đã được <%=this._MethodName.ToLower() %> thành công. Vui lòng kiểm tra lại.</div>
<%} %>
</form>
<%} %>